﻿using CKS.AGV.Core.Enum;
using CKS.Core.Framework;
using CKS.Models;
using CKS.PLC.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CKS.AGV.Core.PlcActions.OP50
{
    /// <summary>
    /// 请求取料
    /// </summary>
    public class RequestMaterialRetrieval : BasePlcAction
    {
        public RequestMaterialRetrieval(DecodeValue _value) : base(_value)
        {
        }

        public override void Execute()
        {
            var pos = Value.Position;
            var partType =Value.GetLinkData(1).ToInt();
            var Signal = Value.Value.ToInt();
            string taskName = "OP50取-";
            
            if (Signal > 0 )
            {
                var StartPlcId = 5;
                var EndPlcId = 0;
                var taskType = 2; // 1送满料 2取空子蓝
                //生成输送任务
                GenerateConveyTask(partType, taskName, StartPlcId, EndPlcId, taskType,pos.LocationId);
            }
            else if (Signal == 0)
            {
                //复位
                var reply1 = Value.GetPosition(3200, pos.ActionId, 1);
                var reply2 = Value.GetPosition(3200, pos.ActionId, 2);
                var reply3 = Value.GetPosition(3200, pos.ActionId, 3);
                var reply4 = Value.GetPosition(3200, pos.ActionId, 4);
                WriteInt16(reply1, 0);
                WriteInt16(reply2, 0);
                WriteInt16(reply3, 0);
                WriteInt16(reply4, 0);
            }
        }

       

    

        
    }
}
